﻿using GameData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TNServer
{
    /// <summary>
    /// 号码管理器
    /// </summary>
    public class NumberManager
    {

        public static NumberManager instance;

        public GlobalVO MainVO;

        public NumberManager(GlobalVO globalVO)
        {
            MainVO = globalVO;
        }


        public NumberInfo CreateNumber(string groupstr="",bool isvip = false, int spnum = -1)
        {
            NumberInfo nf = new NumberInfo();
            string findgroup = "";
            if (Application.MainVO.batchList.Contains(groupstr))
            {
                findgroup = groupstr;
            }
            else
            {
                findgroup = Application.MainVO.SetDataDic["批次"];
            }

            nf.@group = findgroup;
            nf.groupTag = MainVO.GetGroupTag(nf.@group);
            nf.state = (int)NumberState.Receive;
            MainVO.CurNumber += 1;
            if (spnum == -1)
            {

                if (MainVO.SetDataDic["连号"]=="是")
                {
                    int dx = 0;
                    foreach (var p in MainVO.CurIndxDic)
                    {
                        if (dx< p.Value)
                        {
                            dx = p.Value;
                        }
                    }
                    dx += 1;
                    foreach (var p in MainVO.CurIndxDic)
                    {
                        MainVO.CurIndxDic[p.Key] = dx;
                    }
                    nf.value = dx;
                    Console.WriteLine(MainVO.SetDataDic["连号"]+"------ 连号----:" + findgroup + " " + nf.value);

                }
                else
                {

                    int indx = MainVO.GetCurIndx(findgroup);
                    indx += 1;
                    Console.WriteLine("------ find----:" + findgroup+" "+ indx);

                    MainVO.SetCurIndx(findgroup, indx);
                    nf.value = indx;



                }

            }
            else
            {
                nf.value = spnum;
            }
            nf.isVIP = isvip;

            if (spnum != -1)
            {
                if (Application.MainVO.checkInRec(nf)
|| Application.MainVO.checkInVIP(nf)
|| Application.MainVO.checkInCancle(nf)
|| Application.MainVO.checkInComplete(nf)
|| Application.MainVO.checkInDue(nf)
|| Application.MainVO.checkInPick(nf))
                {



                }

            }
            else
            {
                while (Application.MainVO.checkInRec(nf)
|| Application.MainVO.checkInVIP(nf)
|| Application.MainVO.checkInCancle(nf)
|| Application.MainVO.checkInComplete(nf)
|| Application.MainVO.checkInDue(nf)
|| Application.MainVO.checkInPick(nf)
|| Application.ExcelDataManager.vipHasDic[findgroup].Contains(nf.value))
                {
                    nf.value += 1;

                }

            }
            //

            nf.QueueNum =0;
            MainVO.AddNumToReceive(nf);
            MainVO.AllRDic.Add(nf);
            if (isvip)
            {
                MainVO.VipDic.Add(nf);
            }
            Console.WriteLine("------ 新增----:" + findgroup + " " + nf.value);


            return nf;

        }




    }
}
